<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0
        }

        body {
            height: 3000px;
        }

        .box1 {
            width: 650px;
            height: 200px;
            background: paleturquoise;
            margin: 0 auto;
        }

        #searchBox {
            width: 650px;
            height: 40px;
            border: 2px solid orangered;
            border-radius: 40px;
            position: fixed;
            top: 200px;
            left: 50%;
            transform: translateX(-50%);
            display: none;

        }

        .box {
            width: 70px;
            height: 40px;
            background: #eee;
            float: left;
            border-radius: 40px 0 0px 40px;
            display: flex;
            justify-content: center;
            align-items: center;


        }

        .box {
            font-size: 12px;
        }

        #txt {
            display: block;
            float: left;
            width: 500px;
            height: 40px;
            outline: none;

        }

        #btn {
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 16px;
            background: orangered;
            width: 80px;
            color: #fff;
            height: 40px;
            border-radius: 0 40px 40px 0;
            outline: none;
            overflow: hidden
        }
    </style>
</head>

<body>
    <div class="box1"></div>
    <div id="searchBox">
        <div class="box">
            <p>天猫</p>
        </div>
        <input type="search" id="txt">
        <button id="btn">搜索</button>
    </div>

    <script>
        searchBox.style.display = 'block';
        window.onscroll = function () {
            if (scrollY >= 300) {
                searchBox.style.position = 'fixed';
                searchBox.style.top = 0 + 'px';
                searchBox.style.left = '50%';
                searchBox.style.transform = 'translateX(-50%)';
                searchBox.style.display = 'block'
            }
            else {
                searchBox.style.position = 'fixed';
                searchBox.style.top = 200 + 'px';
                searchBox.style.left = '50%';
                searchBox.style.transform = 'translateX(-50%)';
                searchBox.style.display = 'block'
            }
        }
    </script>
</body>

</html>